#include<bits/stdc++.h>
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#ifndef OVERFLOW
	#define OVERFLOW -2
#endif
#define MaxSize 50
typedef  int Status;
typedef	char ElemType;
typedef  int Status;

using namespace std;
typedef struct {
	ElemType data[MaxSize];
	int top;
} SqStack;
//初始化
//typedef struct{
//	ElemType data[MaxSize];//数组存数据
//	int top;//记录栈顶指针
//}SqStack;
//初始化
void InitStack(SqStack &S)
{
	S.top = -1;

}
//站空
Status StackEmpty(SqStack &S)
{
	if (S.top == -1) {
		return OK;
	} else {
		return ERROR;
	}
}
//入栈
Status Push(SqStack &S, ElemType x)
{
	if (S.top == MaxSize - 1) {
		return OVERFLOW;
	}
	S.data[++S.top] = x;
	return OK;
}
//出站
Status Pop(SqStack &S, ElemType &x)
{
	if (S.top == -1) {
		return ERROR;
	}
	x = S.data[S.top--];
	return OK;

}
Status GetTop(SqStack &S, ElemType &x)
{
	if (S.top == -1) {
		return ERROR;
	}
	x = S.data[S.top];

	return OK;
}
int main()
{
	printf("请输入含括号表达式:\n");
	char TopData;
	char x[MaxSize];
	SqStack sq;
	int i;
	InitStack(sq);
	gets(x);
	for (i = 0; i <= MaxSize; i++) {
		if (x[i] == '(')	{Push(sq, x[i]);continue;}
		if (x[i] == '[')	{Push(sq, x[i]);continue;}
		if (x[i] == ')') {
			GetTop(sq, TopData);
			if (TopData != '(') {
				break;
			}
			Pop(sq,TopData);
		}
		if (x[i] == ']') {
			GetTop(sq, TopData);
			if (TopData != '[') {
				break;
			}
			Pop(sq,TopData);
		}

	}
	if (StackEmpty(sq) == 1) {
		printf("括号匹配成功");
	}else{
		printf("括号配对失败");
	}

//	while(cin>>x){
//
//	}
	return 0;
}
